#!/usr/bin/env bash

DOCKER_IMAGE=ycsm-server
SERVICE_NAME=ycsm-server
SERVICE_PORT=9102
VERSION="1.0.`date +%Y%m%d%H%M`"
docker build -t $DOCKER_IMAGE:$VERSION .
rm -f docker-images.tar
if [ $(docker service ls |grep "$SERVICE_NAME:" | wc -l) -gt 0 ]; then docker service update --force -q --image $DOCKER_IMAGE:$VERSION $SERVICE_NAME; \
else docker service create -p $SERVICE_PORT:8080 --name $SERVICE_NAME $DOCKER_IMAGE:$VERSION; fi
docker image prune -f
